package com.hamilton.erik.pt.core.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateTimeUtil {

	private static final String STANDARD_DATE_FORMAT = "MM/dd/yyyy";
	private static final String STANDARD_TIME_FORMAT = "hh:mm a";
	private static final String STANDARD_DATE_TIME_FORMAT =
						String.format("%s %s",
								STANDARD_DATE_FORMAT, STANDARD_TIME_FORMAT);
	
	private static DateTimeUtil instance = null;
	
	public static DateTimeUtil getInstance() {
		if(instance == null) {
			instance = new DateTimeUtil();
		}
		
		return instance;
	}

	private DateTimeUtil() {}
	
	public static String dateToStandardDateString(Date date) {
		return dateToString(STANDARD_DATE_FORMAT, date);
	}
	
	public static Date standardDateStringToDate(String dateString) throws ParseException {
		return stringToDate(STANDARD_DATE_FORMAT, dateString);
	}
	
	public static String dateToStandardDateTimeString(Date date) {
		return dateToString(STANDARD_DATE_TIME_FORMAT, date);
	}
	
	public static Date standardDateTimeStringToDate(String dateString) throws ParseException {
		return stringToDate(STANDARD_DATE_TIME_FORMAT, dateString);
	}
	
	public static String dateToString(String format, Date date) {
		return (new SimpleDateFormat(format)).format(date);
	}
	
	public static Date stringToDate(String format, String dateString) throws ParseException {
		Date date = (new SimpleDateFormat(format)).parse(dateString);
		
		return date;
	}
	
}
